package pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

/**
 * Created by с246 on 04.07.2014.
 */
public class TicketsPage extends HomePage{

        private static final String adultsTicketsLocator = "//div[@class='adults_block passengers_wrapper']/div[@class='persons']/div[%d]";
    private static final String childrenTicketsLocator = "//div[@data-field='children passengers_wrapper']/div[@class='persons']/div[%d]";
    private static final String infantsTicketsLocator = "//div[@class='infants_block passengers_wrapper']/div[@class='persons']/div[%d]";
    private static final By errorPoup = By.className("error_popup");

    private static final By findBtn = By.id("start_search");
    public TicketsPage(WebDriver driver)
    {
        super(driver);
        URL = "http://rozetka.com.ua/travel/IEV/MOW/";
    }

    public void buyTickets(int adults, int children, int infant)
    {
        WebDriverWait wait = new WebDriverWait(driver, 25);
        wait.until(ExpectedConditions.elementToBeClickable(By.xpath(String.format(adultsTicketsLocator,adults))));
        driver.findElement(By.xpath(String.format(adultsTicketsLocator,adults))).click();
        driver.findElement(By.xpath(String.format(childrenTicketsLocator,children))).click();
        driver.findElement(By.xpath(String.format(infantsTicketsLocator,infant))).click();
        driver.findElement(findBtn).click();
    }

    public boolean isError()
    {
        return driver.findElements(errorPoup).size()>0;
    }
}
